package com.ruixin.mvc.parser;

import com.ruixin.annotation.Parser;
import com.ruixin.base.exception.BaseException;
import com.ruixin.base.util.BeanUtil;
import com.ruixin.mvc.annotation.Web;
import com.ruixin.mvc.config.ApplicationContextWrapper;
import com.ruixin.mvc.config.WebMapping;
import com.ruixin.parser.BeanParser;

import java.lang.annotation.Annotation;

@Parser(annotation = Web.class)
public class WebParser extends BeanParser {

    public WebParser(ApplicationContextWrapper context, Class<? extends Annotation> type) {
        super(context, type);
    }

    @Override
    public void parseClass(Class<?> clz) throws BaseException {
        super.parseClass(clz);
        Web annotation = BeanUtil.getAnnotation(clz, Web.class);
        boolean jsonResult = annotation.jsonResult();
        String path = annotation.path();
        WebMapping webMapping = new WebMapping(path,jsonResult);
        ((ApplicationContextWrapper)this.context).setWebMapping(clz,webMapping);
    }
}
